<link rel="stylesheet" href="${request.contextPath}/static/oms/iframe/plugins/minicolors/jquery.minicolors.css" type="text/css">
<div class="row">
	<div class="col-md-12">
		<form id="edit-form" class="form-horizontal" action="${request.contextPath}/oms/ucenter/group/update" method="post" onsubmit="return false">
			<input type="hidden" id="id" name="id" value="${group.id}">
			<div class="box-body" >
				<div class="form-group">
					<label for="group-name" class="col-sm-2 control-label">组名称</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="name" id="group-name" value="${group.name}" placeholder="输入组名称...">
					</div>
					<label for="group-code" class="col-sm-2 control-label" >编码</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="code" id="group-code" value="${group.code}"  placeholder="输入编码...">
					</div>
				</div>
				<div class="form-group">
					<label for="group-icon" class="col-sm-2 control-label">图标</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="icon" id="group-icon" value="${group.icon}" placeholder="输入图标...">
					</div>
					<label for="group-icon-quantity" class="col-sm-2 control-label" >图标数量</label>
					<div class="col-sm-4">
						<input type="number" class="form-control" name="iconQuantity" id="group-icon-quantity" value="${group.iconQuantity}" placeholder="输入图标数量...">
					</div>
				</div>
				<div class="form-group">
					<label for="group-color" class="col-sm-2 control-label">图标颜色</label>
					<div class="col-sm-4">
						<input  type="text" id="group-color" class="form-control color-input" name="color" data-opacity=".5" value="${group.color}" placeholder="选择图标颜色...">
					</div>
				</div>
				<div class="form-group">
					<label for="group-credits-higher" class="col-sm-2 control-label">额度上限</label>
					<div class="col-sm-4">
						<input type="number" class="form-control" name="creditsHigher" id="group-credits-higher" value="${group.creditsHigher}" placeholder="输入额度上限...">
					</div>
					<label for="group-credits-lower" class="col-sm-2 control-label" >额度下限</label>
					<div class="col-sm-4">
						<input type="number" class="form-control" name="creditsLower" id="group-credits-lower" value="${group.creditsLower}" placeholder="输入额度下限...">
					</div>
				</div>
				<div class="form-group">
					<label  for="group-type" class="col-sm-2  control-label">组类型</label>
					<div class="col-sm-4">
						<select class="form-control" id="group-type"  name="type" style="width: 100%;">
						</select>
					</div>
					<label  for="group-status" class="col-sm-2  control-label">状态</label>
					<div class="col-sm-4">
						<select class="form-control" id="group-status"  name="status" style="width: 100%;">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="serverDescriptionLabel" class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="description" id="serverDescription" value="${group.description}" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="serverRemarkLabel" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="remark" id="serverRemark" value="${group.remark}"  placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" id="addFormErrorMsgContainer">
					<span class="error-icon"></span>
					<span id="addFormErrorMsg" class="error-msg" ></span>
				</div>
			</div>
			<div class="box-footer">
				<div class="pull-right">
               		<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 更新</button>
               		<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>
				</div>
          	</div>
		</form>
	</div>
</div>
<script type="text/javascript" src="${request.contextPath}/static/oms/iframe/plugins/minicolors/jquery.minicolors.min.js"></script>
<script type="text/javascript">
function ajaxSubmit(form) {
	var $form = $(form);
	if ($form.length === 1 && $form.validate()) {
        $.ajax({
            type: 'post',
            url: form.action,
            dataType: "json",
            data: $form.serialize()
        }).done(function(result){
            if (result.success) {
                $("#lgModal").modal('hide');
                alertMsg(result.message,"success");
                dataGridReload();
            } else {
                $form.find(".error-msg").show();
                $form.find(".error-msg").html(result.message);
            }
        });
	}
}

$(function() {

    $('.color-input').each( function() {
        //
        // Dear reader, it's actually very easy to initialize MiniColors. For example:
        //
        //  $(selector).minicolors();
        //
        // The way I've done it below is just for the demo, so don't get confused
        // by it. Also, data- attributes aren't supported at this time...they're
        // only used for this demo.
        //
        $(this).minicolors({
            control: $(this).attr('data-control') || 'hue',
            defaultValue: $(this).attr('data-defaultValue') || '',
            inline: $(this).attr('data-inline') === 'true',
            letterCase: $(this).attr('data-letterCase') || 'lowercase',
            opacity: $(this).attr('data-opacity'),
            position: $(this).attr('data-position') || 'bottom left',
            change: function(hex, opacity) {
                if( !hex ) return;
                if( opacity ) hex += ', ' + opacity;
                try {
                    console.log(hex);
                } catch(e) {}
            },
            theme: 'bootstrap'
        });

    });

    $("#group-status").select2({
        data: StatusStore,
        placeholder: "请选择...",
        language: "zh-CN",
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    }).val('${group.status}').trigger("change");
    $("#group-type").select2({
        data: GroupTypeStore,
        placeholder: "请选择...",
        language: "zh-CN",
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    }).val('${group.type}').trigger("change");

	var $editForm = $("#edit-form");
	$editForm.validate({
        rules: {
            name: {
                required: true
            },
            code: {
                required: true
            }
        },
        messages: {
            username:{
                required:"组名称不能为空！"
            },
            code:{
                required:"编码不能为空！"
            }
        },
		submitHandler:ajaxSubmit,
		errorLabelContainer:".error-msg",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$editForm.find(".error-msg").html(errorList[0].message);
			}else{
				$editForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>